<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<style type="text/css">
div {
	width: 60%;
	background-color: #C4E1FF;
	font-size: 13pt
}

#shared_info {
	background-color: #C4E1FF;
	width: 700px;
}
</style>
<title>个人健康信息</title>

</head>

<body>
	<center>
		<form>
			<center>
				<h1>健康参数分享</h1>
			</center>
			<table id="shared_info">
				<?php

				function show_share_td($field, $health_info)
				{
					echo "<td>";
					echo '<input type="checkbox" class="share_chk" field="'.$field.'" '.( field_shared(get_uid(), $field) ? "checked" : "").'>'."分享&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp".'</input>';
					echo "</td>";
					echo '<td>'.translate_field($field).'</td>';
					echo '<td>';
					echo '<label>'.get_value_of_field($field, $health_info)."</label>";
					echo "</td>";
				}

				while(true)
				{
					$field1 = null;
					$field2 = null;
						
					while(!valid_field($field1 = current($health_info_fields))){
						if(!$field1)
							break;
						next($health_info_fields);
					}
					
					if($field1)
						next($health_info_fields);
						
					while(!valid_field($field2 = current($health_info_fields))){
						if(!$field2)
							break;
						next($health_info_fields);
					}
					
					if($field2)
						next($health_info_fields);

					if(!$field1)
						break;

					echo "<tr>";
					show_share_td($field1, $health_info);
						
					echo "<td>&nbsp&nbsp||&nbsp&nbsp</td>";
						
					if($field2)
					{
						show_share_td($field2, $health_info);
					}
					echo '</tr>';
				}
				?>
			</table>
		</form>
	</center>
	<center>
		<form>
			<center>
				<h1>症状分享</h1>
			</center>
			<table id="shared_info">
				<?php			
				function show_share_symp_td($result, $shared, $index)
				{
					echo '<td>';
					echo '<label>'.$result."&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</label>";
					echo "</td>";
					echo '<td>';
					echo '<input type="checkbox" id="share_symp_chk'.$index.'" style="display:block;float:left" class="share_symp_chk" field="'.$result.'" '.( $shared ? "checked" : "").'></input><label id="share_symp_label'.$index.'">分享&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</label>';
					echo '</td>';
				}
				
				if(count($symptoms) == 0)
				{
					echo '<tr><td><center>无</center></td></tr>';
				}
				
				for($i = 0; $i < count($symptoms); $i++)
				{
					$key = key($symptoms);
					$value = current($symptoms);
					
					echo '<tr>';
					show_share_symp_td($key, $value, $i);
					echo '</tr>';
					next($symptoms);
				}

				?>
			</table>
		</form>
	</center>
	<!-- jquery1_8_0.js 才是真正的jquery的库 -->
	<script type="text/javascript"
		src="<?php echo base_url()?>js/jquery1_8_0.js">
	</script>

	<script language="javascript" type="text/javascript">

	
		function update_share_status(field, data)
	{
		$.post("<?php echo site_url("eager_for_care/update_share_status");?>", {
		    field: field,
		    data: data
		});
	}


	</script>

	<script type="text/javascript">
$(
		function ()
		{

			$("input.share_chk").click(
					function()
					{
						field = $(this).attr("field");
						checked = this.checked;
						update_share_status(field, checked);
					}
					);
			$("input.share_symp_chk").click(
					function()
					{
						field = $(this).attr("field");
						checked = this.checked;
						$.post("<?php echo site_url("personal_health_info_analyse/update_symptom_share");?>", 
								{
								    field: field,
								    checked: checked
						    	}
						);
					}
			);
		}
);

	</script>

</body>
</html>
